//获取ul
let uu = document.querySelector('#container')
//1.发起请求获取列表数据

//2.根据列表数据展示列表内容

//3.需要将商品的productId绑定到元素上

//4.点击元素进行跳转,跳到detail页面 并且要携带productId
let id = getQueryString('productid');
console.log(id)
let el = "";
var proNa1 = "";
fetch('http://chst.vip:1234/api/getproduct?productid=' + id)
    //<a href="../pages/priceSearchListDetail.html?categoryid=${id}&productid=${item.productId}" class="clearfix">
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/;
            console.log(item)
            // //处理图片
            // let r = item.productImg.match(regExp);
            // console.log(r)
            //处理proNa
            let s = item.productName
            console.log(s)
            proNa1 = s.substring(0, s.indexOf(" ") + 1)
            console.log(proNa1)
            el += `
            <div class="pic">
                ${item.productImg}
            </div>
            <div class="title">
                ${item.productName}
            </div>
            <div class="lowPrice">
                <span>当前最低</span>
                <span>¥6000</span>
            </div>
            <div class="commit">
                <span>优选评论</span>
                <span>8266条</span>
            </div>
            <div class="BYO">
                ${item.bjShop}
            </div>
            `
        })
        uu.innerHTML = el;
    })
setTimeout(function () {
    let what = document.querySelector("#what")
    let id2 = getQueryString('categoryid');
    let el2 = ""
    // console.log(12323)
    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid=' + id2)
        .then(body => body.json())
        .then(res => {
            console.log(res)
            res.result.forEach(item => {
                let regExp = /(?<=imgurl=)[^'"]*/;
                console.log(item)
                // //处理图片
                // let r = item.productImg.match(regExp);
                // console.log(r)
                el2 = `
                    <p>首页> ${item.category}> ${proNa1}> </p>
                    <button>筛选</button>
                `
            })
            what.innerHTML = el2;
        })
}, 12)


//网友评论
let comment = document.querySelector("#comment")
// let id2 = getQueryString('categoryid');
let el3 = `<div class="topTop">
                网友评论
            </div>`
// console.log(12323)
fetch('http://chst.vip:1234/api/getproductcom?productid=' + id)
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/;
            console.log(item)
            // //处理图片
            // let r = item.productImg.match(regExp);
            // console.log(r)
            el3 += `
                <div class="top">
                    <span class="left">${item.comName}</span>
                    <span class="right">${item.comTime}</span>
                </div>
                <div class="center">
                    <p>${item.comContent}</p>
                </div>
                <div class="bottom">
                    ${item.comFrom}
                </div>
            `
        })
        comment.innerHTML = el3;
    })